<?php
/**
 * 
 * 
 * @version $Id: Sina.php 11 2012-10-12 08:40:34Z linsir123 $
 */
class controllerSina extends WeiboController 
{
	/**
	 * @var 不需要执行[前/后置方法]
	 */
	public $filterActions = array('index', 'callback');
	
	/**
	 * @var 不需要执行[前/后置方法]
	 */
	public $filterType = self::FILTER_DENY;
	
	/**
	 * @var 模型
	 */
	public $model;
	
	/**
	 * 构造函数
	 */
	public function __construct()
	{
		parent::__construct();
		///
		$this->weibo = Weibo::sina();
		$this->model = M::sina();
	}
	
	/**
	 * 前置过滤
	 * // 登录验证
	 */
	public function beforeAction()
	{
		if ( ! $this->weibo->isLogin()) 
			$this->r();
	}
	
	/**
	 * 默认
	 */
	public function actionIndex()
	{
		if ($this->weibo->isLogin()) 
			$this->r('friends');
			
		///
		$oauthUrl = $this->weibo->getOauthUrl();
		
		///
		View::display('sina/home');
		View::assign('oauthUrl', $oauthUrl);
	}
	
	/**
	 * 回调
	 */
	public function actionCallback()
	{
		if ($this->weibo->isLogin() || $this->weibo->doCallback()) 
			$this->r();
		else 
			die('授权失败');
	}
	
	/**
	 * 退出
	 */
	public function actionLogout()
	{
		$this->weibo->logout();
		///
		$this->r();
	}
	
	/**
	 * 取得关注
	 */
	public function actionFriends()
	{
		if (Request::isPost()) {
			$data = $this->model->getFriends();
			$this->ajax($data);
		}
		
		///
		View::display('sina/friends');
	}
	
	/**
	 * 取得关注[僵尸]
	 */
	public function actionFriendsZombie()
	{
		$data = $this->model->getFriendsZombie();
		pr($data);
		
		///
		if (is_array($data)) {
			$_POST['uIds'] = array_slice($data, 0, 15);
			$data = $this->model->destroy();
			pr($data);
		}
		
		///
		View::display('sina/friends-zombie');
	}
}
